# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt

# 数据准备
categories = ['A', 'B', 'C', 'D']
data_sets = {
    'Dataset1': [15, 22, 18, 25],
    'Dataset2': [20, 16, 24, 19],
    'Dataset3': [12, 28, 15, 22],
    'Dataset4': [18, 14, 20, 27]
}

# 创建2x2的子图网格
fig, axes = plt.subplots(2, 2, figsize=(12, 8))
plt.subplots_adjust(wspace=0.3, hspace=0.4)  # 调整子图间距

# 遍历数据绘制子图
for ax, (title, data) in zip(axes.flat, data_sets.items()):
    bars = ax.bar(categories, data, color=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728'])
    ax.set_title(title, fontsize=10)
    ax.set_ylim(0, max(data)*1.1)
    
    # 添加数值标签
    for bar in bars:
        height = bar.get_height()
        ax.text(bar.get_x() + bar.get_width()/2., height,
                f'{height}', ha='center', va='bottom')

plt.suptitle('Multi-Bar Chart Grid Display', y=0.98)
plt.tight_layout()
plt.show()